define(['jquery', 'cm'], function () {
    $('footer').load('../html/footer.html')
    class Money {
        constructor() {
            var user = getCookie('用户')
            var users = JSON.parse(localStorage.getItem('curt'))
            var jugement = users.findIndex((item) => {
                return item.userName == user
            })
            this.data = JSON.parse(localStorage.getItem('store'+jugement)) || []
            // console.log(this.data);
            this.shopList = document.querySelector('.shopList')
            this.button=document.querySelector('.sub')
            this.init()
        }
        init() {
            this.share()
            this.add()
            this.jude()
        }
        jude() {
            console.log($('.login'))
            if (getCookie('用户')) {
                let cookie = getCookie('用户')
                $('.login').html(`<a href="../html/member.html">${cookie}<img src="../imgaes/index/钻石.png" alt=""></a>`)
            }
        }
        share() {
            var str = '<ul>'
            for (var i = 0; i < this.data.length; i++) {
                str += `<li clearfix>
                <div class='left'>
                  <p class='how'>配送方式</p>
                  <p class='quick'>配送方式</p>
                </div>
                <div class='right'>
                  <img src=${this.data[i].img_small_logo}>
                  <div class='cons'>
                  <p class='name'>${this.data[i].title}</p>
                  <p class='note'>1年质保品质有保障,工程师上门服务</p>
                  <p class='product'><i></i>支持七天无忧退换</p>
                 </div>
                 <div class='price'>￥${this.data[i].current_price}</div>
                 <div class='num'>x${this.data[i].cart_number}</div>
                </div>
                
                </li>`
            }
            str += '</ul>'
            this.shopList.innerHTML = str
        }
        add() {
            var number = 0
            var num = 0
            var pastNum = 0
            for (var i = 0; i < this.data.length; i++) {
                num += this.data[i].current_price * this.data[i].cart_number
                pastNum += Number(this.data[i].price) * Number(this.data[i].cart_number)
                number += this.data[i].cart_number
            }
            pastNum = parseInt(pastNum)
            num = parseInt(num)
            // console.log(this.data[2].cart_number);
            var cha = pastNum - num
            $('.setting .right .first').html(`${number}件商品，商品金额<span>￥${num}</span>`)
            $('.setting .right .second').html(`商品原价<span>￥${pastNum}</span>`)
            $('.setting .right .third').html(`优惠<span>￥${cha}</span>`)
            $('.setting .right .four').html(`实付款<span>￥${num}</span>`)
            this.button.addEventListener('click',()=>{
                self.location='../html/givemoney.html'
            })
        }
    }
    new Money()
})